<template>
  <view class="back-color">
    <view class="analyse">
      <view class="title font-bold">结果分析</view>
      <view>本测试及结果由AI得出,仅供参考,不能作为诊断及诊疗的依据</view>
    </view>
    <view class="content" v-for="(item, index) in result_data" :key="index">
      <view class="level">{{ item.scope }}：{{ item.result }}</view>
      <view class="suggest">{{ item.suggest }}</view>
      <!-- 概述 -->
      <view class="font-bold">测评结果概述:</view>
      <view v-for="(subitem, i) in item.outline" :key="i">
        {{ i + 1 }}.{{ subitem }}
      </view>
      <template v-if="item.recommend.length > 0">
        <view class="font-bold">AI为你推荐以下科室</view>
        <view class="recommend" v-for="(subitem, i) in item.recommend" :key="i">
          <label class="flex flex-col">
            <text class="bold">{{ subitem.dep_name }}</text>
            <text class="Hosp">{{ subitem.hospital }}</text>
          </label>
          <label class="regi" @click="regiSter(subitem.dep_id)">去挂号</label>
        </view>
      </template>
    </view>
  </view>
  <!-- 骨架屏 -->
  <view class="submit">
    <button plain="true" open-type="share">邀请朋友测一测</button>
    <button plain="true" @click="agree">再测一次</button>
  </view>
  <skIndex v-if="skeLeton"></skIndex>
</template>

<script setup>
import { onLoad, onShow } from "@dcloudio/uni-app";
import { ref, reactive, onMounted, computed, watch } from "vue";
import apiRequest from "~/api/index";
// 骨架屏
import skIndex from "~/Skeleton/SK-self-test-result.vue";
onLoad((e) => {
  let value = JSON.parse(e.value);
  type.value = value.type;
  answerGroup.value = value.answerGroup;
  console.log(type.value, answerGroup.value);
});
// 心理测试类型
const type = ref("");
const answerGroup = ref([]);
let skeLeton = ref(true);
// 请求数据
onShow(async () => {
  if (type.value === "001") {
    // var顶层属性方便调用
    var res = await apiRequest.depression({ value: answerGroup.value }); // 抑郁症
  } else if (type.value === "002") {
    var res = await apiRequest.premature({ value: answerGroup.value }); // 早泄
  } else if (type.value === "003") {
    var res = await apiRequest.insomnia({ value: answerGroup.value }); // 失眠
  }
  result_data.value = res.data;
  skeLeton.value = false;
});
const result_data = ref([]);

// 去挂号
const regiSter = (dep_id) => {
  uni.navigateTo({
    url: "/pages/doctor/doctor?id=" + dep_id,
  });
};

// 
async function agree(){
  uni.navigateBack({delta:1})
}
</script>

<style>
@import url("../../common-style/form.css");
page {
  background: #f0f5f9;
}
.back-color {
  background: -webkit-linear-gradient(
    top,
    #d6e8ff 30%,
    #f2f7fb 55%,
    #f0f5f9 90%
  );
}
.analyse {
  /* margin: 20rpx; */
  padding: 20rpx;
}
.analyse > .title {
  margin-bottom: 20rpx;
}
.content {
  margin: 20rpx;
  padding: 20rpx;
  border-radius: 10rpx;
  @apply bg-light-50;
}
.content > view {
  margin-bottom: 20rpx;
}
.level {
  @apply text-blue-600 font-bold;
  font-size: 34rpx;
}
.suggest {
  @apply text-blue-300;
}
.recommend {
  @apply bg-gray-100 flex;
  align-items: center;
  padding: 20rpx;
  justify-content: space-between;
}
.recommend .Hosp {
  @apply text-gray-400;
  margin-top: 15rpx;
}
.recommend .regi {
  padding: 20rpx;
  @apply bg-blue-600 text-light-50;
  border-radius: 15rpx;
}
</style>
